from heap.class_member import Method
from jthread.local_vars import LocalVars
from jthread.operand_stack import OperandStack


class JFrame:
    def __init__(self):
        self.preFrame = None
        self.localVars = None
        self.operandStack = None
        self.jThread = None
        self.jMethod = None
        self.nextPc = 0

    @staticmethod
    def newJFrame(thread, method):
        frame = JFrame()
        frame.jThread = thread
        frame.jMethod: Method = method
        frame.localVars = LocalVars.newLocalVars(maxLocals=method.maxLocals)
        frame.operandStack = OperandStack.newOperandStack(maxStack=method.maxStack)
        frame.nextPc = 0
        frame.preFrame = None
        return frame

    def getOperandStack(self):
        return self.operandStack

    def getLocalVars(self):
        return self.localVars

    def getNextPc(self):
        return self.nextPc

    def setNextPc(self, nextPc):
        self.nextPc = nextPc

    def getJThread(self):
        return self.jThread

    def getJMethod(self):
        return self.jMethod

    def setPreFrame(self, preFrame):
        self.preFrame = preFrame

    def getPreFrame(self):
        return self.preFrame

    def revertNextPc(self):
        self.nextPc = self.jThread.getPc()
